package com.open.pokergames.biz.views.admin

import android.os.Bundle
import android.text.InputType
import com.jiangyy.easydialog.CommonDialog
import com.jiangyy.easydialog.InputDialog
import com.open.pokergames.biz.entity.MemberEntity
import com.open.pokergames.biz.views.admin.adapters.MemberListClickItemAdapter
import com.open.pokergames.comm.repository.entity.ResultInfo
import com.open.pokergames.comm.userCenter.UserSearchActivity
import com.sinothk.android.utils.XUtils
import kotlinx.android.synthetic.main.activity_load_recycle_view_load_tip_white_bg_for_search.*
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

class RoomCardAddActivity : UserSearchActivity() {

    private var adapter: MemberListClickItemAdapter? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    }

    override fun retData() {
        if (adapter!!.data != null && adapter!!.data.size > 0) {
            adapter!!.data = null
        }
    }

    override fun setAdapter() {
        adapter = MemberListClickItemAdapter(this)
        adapter!!.setOnSuperListener(this)
        loadingRecyclerView.adapter = adapter
    }

    override fun setAdapterData(data: MutableList<MemberEntity>) {
        adapter!!.data = data
    }

    override fun updateAdapterData(data: MutableList<MemberEntity>) {
        adapter!!.updateData(data)
    }

    override fun onClick(position: Int, itemData: MemberEntity, flag: String?) {
        InputDialog.Builder(this)
            .setTitle("房卡发放")
            .setInputType(InputType.TYPE_CLASS_NUMBER)
            .setHint("请输入房卡数")
            .setLines(1)
            .setPositiveButton(
                "发放"
            ) { view ->

                CommonDialog.Builder(this)
                    .setCancelable(false)
                    .setTitle("房卡发放提示")
                    .setMessage("点击确定后，房卡将直接转给对方！确定发放吗？")
                    .setPositiveButton("确定发放") {

                        showLoadingDialog("正在处理")
                        viewModel!!.addRoomCardAdd(itemData.id, view.tag.toString())

                    }.setNegativeButton("取消") {
                    }.show()
            }
            .setNegativeButton("取消", null)
            .show()
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public fun addRoomCardAddBusCallback(result: ResultInfo<String>) {

        if ("addRoomCardAdd" != result.eventType) {
            return
        }

        hideLoadingDialog()

        when (result.code) {
            ResultInfo.SUCCESS -> {
                XUtils.toast().show("处理成功")
                finish()
            }
            else -> {
                XUtils.toast().show(result.msg)
            }
        }
    }

}